package com.sumc.springcloud.redis.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

/**
 * @describe：
 * @author: Smc
 * @version:v1.0 2020/3/24 11:35   Try to write good code
 */

@Repository
public class RedisDao {


    @Autowired
    private StringRedisTemplate template;

    /**
     * 保存Key  value
     * @param key
     * @param value
     */
    public void setKey(String key,String value){
        ValueOperations<String, String> stringStringValueOperations = template.opsForValue();
        stringStringValueOperations.set(key,value);

    }

    /**
     * 通过key 获取内容
     * @param key
     * @return
     */
    public String getKey(String key){
        ValueOperations<String, String> stringStringValueOperations = this.template.opsForValue();
        return stringStringValueOperations.get(key);
    }



}
